import java.io.IOException;

import javax.servlet.ServletException;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.web.servlet.ModelAndView;

import springbook.temp.ConfigureDispatcherServlet;
import springbook.temp.HelloSpring;

/*
 * 작성일 : 2014. 4. 10.
 * 작성자 : hch1982
 *
 * 설명
*/ 
/**
 * 
 */


/**
 * @author hch1982
 *
 * 코드 수정 히스토리
 * 날짜		작업자		태그
 * 2014. 4. 10.	hch1982	
 */
public class ServletContextTest {
	
	public static void main(String [] args){
		ConfigureDispatcherServlet servlet = new ConfigureDispatcherServlet();
		servlet.setRelativeLocations( ServletContextTest.class , "spring-servlet.xml");
		servlet.setClasses(HelloSpring.class);
		try {
			servlet.init(new MockServletConfig("spring"));
			
			MockHttpServletRequest req = new MockHttpServletRequest("GET", "/hello");
			req.addParameter("name", "Spring");
			MockHttpServletResponse res = new MockHttpServletResponse();
			
			servlet.service(req, res);
			
			ModelAndView mav = servlet.getModelAndView();
			System.out.println("model view name :"+ mav.getViewName());
			System.out.println("message : "+(String)mav.getModel().get("message"));
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
